package com.gitee.xhs.sampleRecod.transactionRecord.jmockTool;

import com.gitee.xhs.sampleRecod.transactionRecord.AbstractTransactionMockerInterceptor;
import com.gitee.xhs.sampleRecod.transactionRecord.Transaction;
import com.github.jsonzou.jmockdata.DataConfig;
import com.github.jsonzou.jmockdata.InterceptType;
import com.github.jsonzou.jmockdata.MockConfig;

import java.lang.reflect.Field;

/**
 * @author BigHead
 * @date 2022/7/19 10:14
 * @description TransactionLoopOneToTenMockerInterceptor
 */
public class TransactionLoopOneToTenMockerInterceptor extends AbstractTransactionMockerInterceptor {

    public static final Integer LOOP_KEY_TEN = 10;

    @Override
    public MockConfig getMockConfig() {
        MockConfig mockConfig = new MockConfig();
        mockConfig.registerBeanMockerInterceptor(Transaction.class, this);
        return mockConfig;
    }

    @Override
    public Object mock(Class<Transaction> clazz, Field field, Transaction bean, DataConfig dataConfig) throws IllegalAccessException {
        int remainder = getDataNum(null) % LOOP_KEY_TEN;
        bean.setAccountId(remainder + 1);
        bean.setTimestamp(System.currentTimeMillis());
        bean.setAmount(0d);
        bean.setDataNum(getDataNum(null));
        return InterceptType.UNMOCK;
    }
}
